package test_net;

import com.google.gson.Gson;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

//必须是抽象类
public abstract class TestHttpListCallback<T> extends AbsTestCallback<HttpResult<List<T>>> {
    @Override
    public HttpResult<List<T>> convert(String json) {
        Type type = getClass().getGenericSuperclass();
        //没定义泛型的时候type转成ParameterizedType会报类型转换错误
        Type[] types = ((ParameterizedType) type).getActualTypeArguments();
        Type listType = new ParameterizedTypeImpl(List.class, new Type[]{types[0]});
        Type ty = new ParameterizedTypeImpl(HttpResult.class, new Type[]{listType});
        return new Gson().fromJson(json, ty);
    }



}
